﻿namespace EasyWeb.Configuration
{
    using System;
    using System.Reflection;

    [Serializable]
    public class EWNavigationNode
    {
        private readonly EWNavigationNodeCollection nodes = new EWNavigationNodeCollection();
        private string id;
        private string name;
        private Type resourceType;
        private string url;
        private string icon;

        public string Id
        {
            get { return this.id; }
            set { this.id = value; }
        }

        public string Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public Type ResourceType
        {
            get { return this.resourceType; }
            set { this.resourceType = value; }
        }

        public string Url
        {
            get { return this.url; }
            set { this.url = value; }
        }

        public string Icon
        {
            get { return this.icon; }
            set { this.icon = value; }
        }

        public EWNavigationNodeCollection Nodes
        {
            get { return this.nodes; }
        }

        public string DisplayName
        {
            get
            {
                if (this.resourceType == null)
                {
                    return this.name;
                }

                var property = this.resourceType.GetTypeInfo().GetProperty(this.name, BindingFlags.FlattenHierarchy | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                return (string)property.GetValue(null, null);
            }
        }
    }
}
